/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 杨已萱
 * Date: 2023-04-06
 * Time: 11:32
 */
public abstract class TestRunTime {
    abstract void run();
    public void test(){
        long starttime = System.nanoTime();
          run();
        long endtime = System.nanoTime();
        System.out.println("运行时间为："+(endtime-starttime));

    }

    public static void main(String[] args) {
        new TestSumTime().test();
        new TestSqureSumTime().test();
    }
}
 class TestSumTime extends TestRunTime{
    @Override
    void run() {
        int sum = 0;
        for (int i = 0; i < 1000; i++) {
            sum += i;
        }
    }
}
class TestSqureSumTime extends TestRunTime {
    @Override
    void run() {
        int sum = 0;
        for (int i = 0; i < 1000; i++) {
            sum += i * i;
        }
    }
}



